package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.model.entity.ApartmentInfo;

import com.atguigu.lease.web.app.service.FacilityInfoService;
import com.atguigu.lease.web.app.service.GraphInfoService;
import com.atguigu.lease.web.app.service.LabelInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private LabelInfoService labelInfoService;
    @Autowired
    private GraphInfoService graphInfoService;
    @Autowired
    private FacilityInfoService facilityInfoService;
    @Autowired
    private ApartmentInfoMapper mapper;
    @Override
    public ApartmentItemVo queryVoById(Long id) {
        List<LabelInfo> labelInfoList=labelInfoService.listInfoByApartmentId(id);
        LambdaQueryWrapper<GraphInfo> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(GraphInfo::getItemId,id).eq(GraphInfo::getItemType, ItemType.APARTMENT);
        List<GraphInfo> graphVoList=graphInfoService.list(wrapper);
        BigDecimal minRent=mapper.selectMinRent(id);
        ApartmentInfo apartmentInfo = getById(id);
        ApartmentItemVo vo=new ApartmentItemVo();
        vo.setGraphVoList(graphVoList);
        vo.setLabelInfoList(labelInfoList);
        vo.setMinRent(minRent);
        BeanUtils.copyProperties(apartmentInfo,vo);
        return vo;
    }

    @Override
    public ApartmentDetailVo getApartmentById(Long id) {
        ApartmentItemVo apartmentItemVo = queryVoById(id);
        List<FacilityInfo> facilityInfoList=facilityInfoService.listInfoByApartmentId(id);
        Boolean isDelete=apartmentItemVo.getIsDeleted()==1;
        ApartmentDetailVo apartmentDetailVo=new ApartmentDetailVo();
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setIsDelete(isDelete);
        BeanUtils.copyProperties(apartmentItemVo,apartmentDetailVo);
        return apartmentDetailVo;
    }
}




